package gold.contest;

import gold.utils.InputUtil;

import java.util.LinkedHashMap;
import java.util.*;
import java.util.Map;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC6114 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public boolean canChange(String start, String target) {
            StringBuilder startBuilder = new StringBuilder(), targetBuilder = new StringBuilder();
            List<Integer> startL = new ArrayList<>(), startR = new ArrayList<>(), targetL = new ArrayList<>(), targetR = new ArrayList<>();
            int len = start.length();

            for (int i = 0; i < len; i++) {
                if (start.charAt(i) == 'L') {
                    startBuilder.append('L');
                    startL.add(i);
                } else if (start.charAt(i) == 'R') {
                    startBuilder.append('R');
                    startR.add(i);
                }

                if (target.charAt(i) == 'L') {
                    targetBuilder.append('L');
                    targetL.add(i);
                } else if (target.charAt(i) == 'R') {
                    targetBuilder.append('R');
                    targetR.add(i);
                }
            }

            if (!startBuilder.toString().equals(targetBuilder.toString())) return false;

            // see positions
            for (int i = 0; i < startL.size(); i++) {
                if (startL.get(i) < targetL.get(i)) return false;
            }

            for (int i = 0; i < startR.size(); i++) {
                if (startR.get(i) > targetR.get(i)) return false;
            }

            return true;
        }
    }

    public void run() {
//        System.out.println(new Solution().canChange("_L__R__R_", "L______RR"));
//        System.out.println(new Solution().canChange("R_L_", "__LR"));
//        System.out.println(new Solution().canChange("_R", "R_"));
//
        System.out.println(new Solution().canChange("_", ""));
    }

    public static void main(String[] args) throws Exception {
        LC6114 an = new LC6114();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
